close all;
%Updated: 8/12/2021

% Plot results from counterfactual exercises

choice_paper=1;      % =1 for plots for paper, =0 otherwise
choice_2models=0;    % =1 plot two models together

cd 'rep_1sd_1.1meanb'        %Exercise 1: debt-financed stimulus

hoff  =load('hoff.txt');
bpoff=load('bpoff.txt');
ctoff =load('ctoff.txt');
gnoff =load('gnoff.txt');
woff  =load('woff.txt');
tauoff=load('tauoff.txt');
wwoff =load('wwoff.txt');
qoff  =load('qoff.txt');
g     =load('gnoff.txt');
waut  =load('waut.txt');

cd ..

b     =load('bgrid2.txt');
a     =load('agrid2.txt');

defoff = zeros(size(woff));

[iw] = find(woff>=waut);            %determine interval over which repayment is optimal

defoff(iw)=1;

nb   = size(b,1);
na   = size(a,1);

alpha   = 0.75;
gamma   = 0.43;
omega   = 0.3;
taxrate = 0.19;
lambda  = 0.184;
r       = 0.02;
mu      = 1;

cnoff   = hoff.^alpha-gnoff;
pnoff   = (1-omega)/omega*(ctoff./cnoff).^(1+mu);
spoff   = ((1+qoff.^(-1)-lambda)./(1+r)-1)*100;
debtoff = -bpoff/(lambda+r);
fdoff   = pnoff.*gnoff-tauoff;              %primary fiscal deficit
taxoff  = taxrate.*(exp(a(11))+pnoff.*(hoff.^alpha));

disp('debt-financed stimulus');

[i1]=find(hoff>0);

idxmax = find(woff(i1) == max(woff(i1)));

NameArray = {'MarkerFaceColor','MarkerSize'};
ValueArray1 = {'b';8}';

xmin  = 0.19;
xmax  = 0.22;
xmin2 = 0.185;
xmax2 = 0.225;
xdif  = 0.01;
    
NameArray1 = {'LineStyle','Color','LineWidth'};
ValueArray1 = {'-';[0.078  0.1686  0.549];2}';

NameArray2 = {'MarkerFaceColor'};
ValueArray2 = {[0.078  0.1686  0.549]}';

label_debt='paper_gn';    
nameFig = char(['util' '_' char(label_graph) '_' char(label_debt)]);
figure('name',nameFig);
P=plot(g(i1),woff(i1),'-b','LineWidth',2); hold on;
PP=plot(g(i1(idxmax)),woff(i1(idxmax)),'bo','MarkerFaceColor','b','MarkerSize',16); 
AX1 = gca;box on;set(AX1,'XTick',xmin:xdif:xmax,'FontSize',16,'XLim',[xmin2 xmax2]);
set(AX1,'YTick',-14.75:0.05:-14.65 ,'YLim',[-14.75 -14.65],'FontSize',16);xlabel('$g^N$','FontSize',16,'Interpreter','latex');
set(P,NameArray1,ValueArray1);grid on;
set(PP,NameArray2,ValueArray2);
set(gcf, 'Units', 'Inches', 'Position', [2, 2, 7, 5]); %[initial x position, initial y position, width, height]
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);

nameFig = char(['unemp' '_' char(label_graph) '_' char(label_debt)]);
figure('name',nameFig);
P=plot(g(i1),100*(1-hoff(i1)),'-b','LineWidth',2);ylabel('%','FontSize',16);
hold on
PP=plot(g(i1(idxmax)),100*(1-hoff(i1(idxmax))),'bo','MarkerFaceColor','b','MarkerSize',16); 
set(P,NameArray1,ValueArray1);grid on;
set(PP,NameArray2,ValueArray2);
AX1 = gca;box on;set(AX1,'XTick',xmin:xdif:xmax,'FontSize',16,'XLim',[xmin2 xmax2]);
set(AX1,'YTick',0:10:20,'YLim',[0 20],'FontSize',16);xlabel('$g^N$','FontSize',16,'Interpreter','latex');
set(gcf, 'Units', 'Inches', 'Position', [2, 2, 7, 5]); %[initial x position, initial y position, width, height]
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);

nameFig = char(['cn' '_' char(label_graph) '_' char(label_debt)]);
figure('name',nameFig);
P=plot(g(i1),cnoff(i1),'-b','LineWidth',2);hold on
PP=plot(g(i1(idxmax)),cnoff(i1(idxmax)),'bo','MarkerFaceColor','b','MarkerSize',16); 
set(P,NameArray1,ValueArray1);grid on;
set(PP,NameArray2,ValueArray2);
AX1 = gca;box on;set(AX1,'XTick',xmin:xdif:xmax,'FontSize',16,'XLim',[xmin2 xmax2]);
set(AX1,'YTick',0.65:0.05:0.75,'YLim',[0.65 0.75],'FontSize',16);xlabel('$g^N$','FontSize',16,'Interpreter','latex');
set(gcf, 'Units', 'Inches', 'Position', [2, 2, 7, 5]); %[initial x position, initial y position, width, height]
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);

nameFig = char(['pn' '_' char(label_graph) '_' char(label_debt)]);
figure('name',nameFig);
P=plot(g(i1),pnoff(i1),'-b','LineWidth',2);hold on
PP=plot(g(i1(idxmax)),pnoff(i1(idxmax)),'bo','MarkerFaceColor','b','MarkerSize',16); 
set(P,NameArray1,ValueArray1);grid on;
set(PP,NameArray2,ValueArray2);
AX1 = gca;box on;set(AX1,'XTick',xmin:xdif:xmax,'FontSize',16,'XLim',[xmin2 xmax2]);
set(AX1,'YTick',3.8:0.1:4.1,'YLim',[3.8 4.1],'FontSize',16);xlabel('$g^N$','FontSize',16,'Interpreter','latex');
set(gcf, 'Units', 'Inches', 'Position', [2, 2, 7, 5]); %[initial x position, initial y position, width, height]
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);

nameFig = char(['sp' '_' char(label_graph) '_' char(label_debt)]);
figure('name',nameFig);
P=plot(g(i1),spoff(i1),'-b','LineWidth',2);ylabel('%','FontSize',16);hold on
PP=plot(g(i1(idxmax)),spoff(i1(idxmax)),'bo','MarkerFaceColor','b','MarkerSize',16); 
set(P,NameArray1,ValueArray1);grid on;
set(PP,NameArray2,ValueArray2);
AX1 = gca;box on;set(AX1,'XTick',xmin:xdif:xmax,'FontSize',16,'XLim',[xmin2 xmax2]);
set(AX1,'YTick',0:3:6,'YLim',[0 6],'FontSize',16);xlabel('$g^N$','FontSize',16,'Interpreter','latex');
set(gcf, 'Units', 'Inches', 'Position', [2, 2, 7, 5]); %[initial x position, initial y position, width, height]
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);

nameFig = char(['debt' '_' char(label_graph) '_' char(label_debt)]);
figure('name',nameFig);
P=plot(g(i1),debtoff(i1),'-b','LineWidth',2);hold on
PP=plot(g(i1(idxmax)),debtoff(i1(idxmax)),'bo','MarkerFaceColor','b','MarkerSize',16); 
set(P,NameArray1,ValueArray1);grid on;
set(PP,NameArray2,ValueArray2);
AX1 = gca;box on;set(AX1,'XTick',xmin:xdif:xmax,'FontSize',16,'XLim',[xmin2 xmax2]);
set(AX1,'YTick',1.1:0.1:1.3,'YLim',[1.1 1.3],'FontSize',16);xlabel('$g^N$','FontSize',16,'Interpreter','latex');
set(gcf, 'Units', 'Inches', 'Position', [2, 2, 7, 5]); %[initial x position, initial y position, width, height]
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);

return
